package com.itjiange.reglg.config;

import com.itjiange.reglg.interceptor.IPInterceptor;
import com.itjiange.reglg.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * 拦截器配置
 *
 * @author ItJiange
 * @date 2023/11/17
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final List<String> allowPath = List.of("/userInfo/logByUsername",
            "/userInfo/logByEmailOrPhone", "/userInfo/logByEmailOrPhone");

    @Autowired
    private IPInterceptor ipInterceptor;

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(ipInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns();
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns(allowPath);
    }
}
